package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.Annoation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    //新增菜品需要
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);



    @AutoFill(OperationType.INSERT)
    void adddish(Dish dish);

    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);


    
    @Select("select * from  dish where id=#{id}")
    Dish getById(Long id);


    //根据主键id删除菜品
    @Delete("delete from sky_take_out.dish where id=#{id}")
    void DeleteById(Long id);

    //批量删除dish
    void DeleteByIds(List<Long> ids);


    void update(Dish dish);

    //根据id来修改菜品售卖状态
    @Update("update dish set status = #{status} where id = #{id}")
    void closeoropen(Integer status,Long id);

    //根据分类id查询菜品
    List<Dish> list(Dish dish);

    //连接条件：a.id = b.dish_id。 过滤条件：where b.setmeal_id = #{setmealId} 指定套餐 ID。
    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);

    Integer countByMap(Map map);
}
